package com.samoiloff.ui.list.smart.view {
	import com.samoiloff.ui.common.Viewport;
	import com.samoiloff.ui.list.smart.interfaces.CellRenderer;
	import com.samoiloff.util.data.ArrItem;

	import flash.display.Sprite;

	/**
	 * @author Samoiloff
	 */
	public class SmartListViewport extends Viewport {
		
		private var _arr: ArrItem;

		public function SmartListViewport() {
			_arr = new ArrItem();
		}
		
		public function addItem(cell: CellRenderer): void {
			cell.visible = true;
			_mc.addChild(cell.mc);
			_arr.addItem(cell);
		}

		public function removeItem(cell: CellRenderer): void {
			_mc.removeChild(cell.mc);
			cell.visible = false;
			_arr.removeItem(cell);
		}
		
		public function removeItemAt(i:int):void {
			var cell:CellRenderer = _arr.removeItemAt(i) as CellRenderer;
			_mc.removeChild(cell.mc);
			cell.visible = false;
			
		}

		public function getItemAt(i:int ):CellRenderer {
			return _arr.toArray()[i] as CellRenderer;
		}
		
		public function get length():int {
			return _arr.length;
		}

		public function get mc(): Sprite {
			return _mc;
		}
	}
}
